package com.example.springcloudeurekaserverproducer.services.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Optional;

import com.example.springcloudeurekaserverproducer.DAO.KanbanPolicepresonDAO;
import com.example.springcloudeurekaserverproducer.DTO.KanbanPolicepresonDTO;
import com.example.springcloudeurekaserverproducer.services.KanbanPolicepresonServices;
import com.example.springcloudeurekaserverproducer.vo.KanbanPolicepreson;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("kanbanPolicepresonServices")
public class KanbanPolicepresonServiceImpl implements KanbanPolicepresonServices {
	@Autowired
	private KanbanPolicepresonDAO<KanbanPolicepresonDTO> kanbanPolicepresonDAO;
	@Override
	public int insert(KanbanPolicepreson po) {
		KanbanPolicepresonDTO dto = new KanbanPolicepresonDTO();
		try {
			BeanUtils.copyProperties(dto, po);
			int insert = kanbanPolicepresonDAO.insert(dto);
			return insert;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int update(KanbanPolicepreson po) {
		KanbanPolicepresonDTO dto = new KanbanPolicepresonDTO();
		try {
			BeanUtils.copyProperties(dto, po);
			int insert = kanbanPolicepresonDAO.update(po);
			return insert;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int delete(KanbanPolicepreson po) {
		KanbanPolicepresonDTO dto = new KanbanPolicepresonDTO();
		try {
			BeanUtils.copyProperties(dto, po);
			int insert = kanbanPolicepresonDAO.delete(dto);
			return insert;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public List<KanbanPolicepreson> select(KanbanPolicepreson po) {
		KanbanPolicepresonDTO dto = new KanbanPolicepresonDTO();
		try {
			BeanUtils.copyProperties(dto, po);
			 List<KanbanPolicepreson> list = (List<KanbanPolicepreson>) kanbanPolicepresonDAO.select(po);
			return  list;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public KanbanPolicepreson queryById(KanbanPolicepreson po) {
		KanbanPolicepresonDTO dto = new KanbanPolicepresonDTO();
		try {
			BeanUtils.copyProperties(dto, po);
			KanbanPolicepreson info =  (KanbanPolicepreson) kanbanPolicepresonDAO.queryById(dto);
			return  info;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return null;
	}

}
